package com.disruptor.demo.event;

import com.disruptor.demo.model.SeriesData;
import com.disruptor.demo.model.TestData;
import com.disruptor.demo.queue.SeriesDataEventQueueHelper;
import com.disruptor.demo.queue.TestDataEventQueueHelper;

/**
 * @author <a href="mailto:HelloHeSir@gmail.com">Mr_He</a>
 * @Copyright (c)</ b> HeC<br/>
 * @createTime 2018/8/2 19:46
 * @Description:
 */
public class TradeEvent implements Runnable {

    private TestDataEventQueueHelper testDataEventQueueHelper;

    private SeriesDataEventQueueHelper seriesDataEventQueueHelper;

    private Integer type;

    private Integer deviceData;

    public TradeEvent(TestDataEventQueueHelper testDataEventQueueHelper, SeriesDataEventQueueHelper seriesDataEventQueueHelper, Integer type, Integer deviceData) {
        this.testDataEventQueueHelper = testDataEventQueueHelper;
        this.seriesDataEventQueueHelper = seriesDataEventQueueHelper;
        this.type = type;
        this.deviceData = deviceData;
    }

    @Override
    public void run() {
        if (type == 1) {
            for (int i = 0; i < deviceData; i++) {
                testDataEventQueueHelper.publishEvent(new TestData(i + ""));
            }
        } else {
            for (int i = 0; i < deviceData; i++) {
                seriesDataEventQueueHelper.publishEvent(new SeriesData(i + ""));
            }
        }

    }
}